﻿using System;
using System.Collections.Generic;

namespace SortOf
{
    //class SelectionSort<T> where T : IComparable
    public class SelectionSort
    {
        public static T[] Sort<T>(T[] list) where T : IComparable
        {
            int k;
            T temp;

            for (int i = 0; i < list.Length; i++)
            {
                k = i;
                for (int j = i + 1; j < list.Length; j++)
                {
                    // checkt of list[k] kleiner is dan list[j]
                    if (list[j].CompareTo(list[k]) < 0)
                    {
                        k = j;
                    }
                }
                // wisselt list[i] met list[k]
                // m.a.w. het huidige getal in de array wordt geswitched met het kleinste getal
                temp = list[i];
                list[i] = list[k];
                list[k] = temp;

                for (int z = 0; z < list.Length; z++)
                {
                    Console.Write(list[z] + " ");
                }
                Console.WriteLine();

            }
            return list;
        }
    }
}
